<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>不锈钢按钮</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            list-style: none;
        }
        body,html{
            height: 100%;
            background: #aaa;
        }
        .button-wrap{
            width: 300px;
            height: 100px;
            border-radius: 50px;
            position: absolute;
            overflow: hidden;
            border-radius: 60px;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
        .button{
            width: 100%;
            height: 100%;
            overflow: hidden;
            border-radius: 60px;
            cursor: pointer;
            background-color: #eee;
        }
        .button:active{
            transform: scale(0.95);
            box-shadow: 0px 1px 1px rgba(0,0,0,0.5);
        }
        .button-reflection{
            width: 100%;
            height: 100%;
            object-fit: cover;
            opacity: 0.7;
            /* 模糊，饱和度，亮度 */
            filter: blur(3px) saturate(0.4) brightness(1.1);
        }
        .text{
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            pointer-events: none;
            color: rgba(0,0,0,0.7);
            font-size: 30px;
            font-weight: 500;
            text-shadow: 0px 1px 0px rgba(255,255,255,0.5);
        }
        .fingerprint{
            pointer-events: none;
            z-index: 100;
            position: absolute;
            left: 0;
            top: 0;
            transform: translate(-50%,-50%);
            width: 60px;
            height: 60px;
            background: #aaa5;
            border-radius: 100%;
            mask-image: radial-gradient(50% 50% at 50% 50%,#000 0%,#0000 100%);
            -webkit-mask-image: radial-gradient(50% 50% at 50% 50%,#000 0%,#0000 100%);
        }
        .tip{
            position: absolute;
            width: 100%;
            text-align: center;
            top: 50%;
            transform: translate(0,50px);
            color: red;
        }
    </style>
</head>
<body>
    <div class="button-wrap">
        <div class="fingerprint" style="display: none;"></div>
        <div class="button">
            <video class="button-reflection" ref="container"></video>
        </div>
        <div class="text">不锈钢按钮</div>
    </div>
    <div class="tip">*注意开启摄像头权限</div>
</body>
<script>
    const container = document.querySelector(".button-reflection");
    const fingerprints = [];    // 指纹

    onload = function(){
        navigator.mediaDevices.getUserMedia({
            video:true,
            audio:false
        }).then(stream => {
            const video = container;
            video.srcObject = stream;
            video.onloadedmetadata = function(e){
                video.play();
            };
        })
    }
    let fingerCopy = document.querySelector(".fingerprint");
    document.querySelector(".button").addEventListener("click",(e)=>{
        const btn = container.getBoundingClientRect();
        const finger = {
            x: e.clientX - btn.left,
            y: e.clientY - btn.top
        };
        fingerprints.push(finger);
        let newFinger = fingerCopy.cloneNode(false);
        newFinger.removeAttribute("style");
        newFinger.style.left = finger.x + "px";
        newFinger.style.top = finger.y + "px";
        fingerCopy.parentNode.insertBefore(newFinger,fingerCopy)
    })
</script>
</html>